export default {
	state: {
		info: {
			name: "",
			nickname: "",
			sex: "men",
			ages: 22,
			tell: "0731-88888888",
			header: '',
		},
		token: "RESPONSESETHEADERACCESSCONTROLALLOWORIGIN",
	},
	getters: {
		userinfo: state => {
			return state.user.info;
		}
	},
	mutations: {
		setInfo(state, info) {
			state.info = info;
		},
		edit(state, info) {
			state.info = info;
		}
	},
	actions: {
		increment(context) {
			context.commit('increment')
		},

		/**
		 * @description 设置用户数据
		 * @param {Object} state vuex state
		 * @param {*} info info
		 */
		set({
			state,
			dispatch
		}, info) {
			return new Promise(async resolve => {
				// store 赋值
				state.info = info
				// 持久化
				await dispatch('vsAdmin/db/set', {
					dbName: 'sys',
					path: 'user.info',
					value: info,
					user: true
				}, {
					root: true
				})
				// end
				resolve()
			})
		},
		/**
		 * @description 从数据库取用户数据
		 * @param {Object} state vuex state
		 */
		load({
			state,
			dispatch
		}) {
			return new Promise(async resolve => {
				// store 赋值
				state.info = await dispatch('vsAdmin/db/get', {
					dbName: 'sys',
					path: 'user.info',
					defaultValue: {},
					user: true
				}, {
					root: true
				})
				// end
				resolve()
			})
		}
	},
	module: {

	}
}